package com.chen.pdf;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import com.chen.pdf.util.PdfUtils;

import java.io.File;
import java.util.Date;
import java.util.List;

/**
 * Hello world!
 *
 */
public class App {

    // resources 目录路径
    public static final String RESOURCES_PATH = ClassLoader.getSystemClassLoader().getResource("").getPath();

    // 源文件路径
    public static final String SRC_PATH = RESOURCES_PATH + File.separatorChar+ "src";
    // 输出文件路径
    public static final String OUT_PATH = RESOURCES_PATH + File.separatorChar+ "out";

    public static void main( String[] args ) {
        System.out.println( "hello world!" );

        if(!FileUtil.exist(OUT_PATH)) {
            FileUtil.mkdir(OUT_PATH);
        }

        List<String> fileNameList = FileUtil.listFileNames(SRC_PATH);
        for (String fileName : fileNameList){
            String pdfPath = SRC_PATH+File.separatorChar+fileName;

            String newName = fileName.substring(0,fileName.length()-4) +"_"+ DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN)+".pdf";
            String outFilePath = OUT_PATH+File.separatorChar+newName;

            System.out.println("gen file:"+newName);

            PdfUtils.addPageNum(pdfPath,outFilePath);
        }

        System.out.println("out path:"+OUT_PATH);
        System.out.println("end");
    }
}
